package io.renren.utils;

import io.renren.common.utils.RedisUtils;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class RabbitUtils {

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private MessagePostProcessor messagePostProcessor;

    public void sendMsg(String exchange, String routingKey, Map<String, Object> map) {
        String id = new IdWorker().nextId() + "";
//        String s = redisUtils.get(id);
////        System.out.println(id + " " + s);
//        Integer i = 1;
//        if (StringUtils.isBlank(s)) {
//            redisUtils.set(id, 0, 30);
//        }
////        System.out.println("redis: " + redisUtils.get(id));
        CorrelationData correlationData = new CorrelationData();
        correlationData.setId(id);
        rabbitTemplate.convertAndSend(exchange, routingKey, map,messagePostProcessor, correlationData);
    }
}
